var types = new Array();//常用项类型id
	var typesid;	
$(function() {
	var rowNum = 1;


	$("#handdatagrid").datagrid({
		rownumbers: false,
		nowrap: false,
		border: true,
		border: true,
		width: $(window).width(),
		toolbar: '#xctGridToolbar',
	})
	var handdatagridPanel = $("#handdatagrid").datagrid("getPanel");
	handdatagridPanel.on("click", "a.add", function() {
		$("#xctdlgadd").dialog({
			buttons: [{
					text: "添加",
					iconCls: "icon-save",
					handler: function() {
						rowNum = rowNum + 1;
						var table = "<div><table class='form_table' id='xctform_table2" + rowNum + "' >" +
							"<tr>" +
							"<td id='td_left' >" +
							"序号：" +
							"</td>" +
							"<td id='td_right'><input class='easyui-textbox'style='width:100%' readonly='readonly' value=" + rowNum + "></td>" +
							"<td  id='td_left'>" +
							"现场图：" +
							"</td>" +
							"<td id='td_right'><input class='easyui-filebox' style='width:100%'  name='file' data-options=" + "buttonText:'选择',prompt:'请选择文件...'" + "  /></td>" +
							"</tr>" +
							"<tr>" +
							"<td id='td_left'>" +
							"现场图类型:"+
							"</td>" +
							'<td class="td_right"><input readonly="readonly"  id="pictype'+rowNum+'" style="width:300px;position: relative;height: 22px;border: 1px solid #D3D3D3;background-color: #fff;vertical-align: middle;display: inline-block;overflow: hidden;white-space: nowrap;margin: 0;padding: 0;-moz-border-radius: 5px 5px 5px 5px;-webkit-border-radius: 5px 5px 5px 5px;border-radius: 5px 5px 5px 5px;" /><img style="margin-top: 5px;" src="../../img/dictselect.gif" onclick="dictselect(pictype'+rowNum+')"/></td>'
							+
							"<td id='td_left'>" +
							"现场图原始文件：" +
							"</td>" +
							"<td  ><input class='easyui-filebox' style='width:100%'  name='file' data-options=" + "buttonText:'选择',prompt:'请选择文件...'" + "  /></td>" +
							"</tr>" +

							"</table></div>"
						$("#xctForm").append(table);
						$.parser.parse($("#xctForm").parent());
					}
				}, {
					text: "删除",
					iconCls: "icon-remove",
					handler: function() {
						if(rowNum == 1) {
							return;
						}
						$("#xctform_table2" + rowNum).remove();
						rowNum = rowNum - 1;
					}
				}, {
					text: "保存",
					iconCls: "icon-save",
					handler: function() {

					}
				}, {
					text: "取消",
					iconCls: "icon-cancel",
					handler: function() {
						$("#xctdlgadd").dialog("close");
					}
				}

			]
		});
		$("#xctdlgadd").dialog("open").dialog('setTitle', '现场图基本信息新增');
	}).on("click", "a.manypicture", function() {
		$("#xctdlgpic").dialog({
			buttons: [{
				text: "添加",
				iconCls: "icon-save",
				handler: function() {

				}
			}, {
				text: "取消",
				iconCls: "icon-cancel",
				handler: function() {
					$("#xctdlgpic").dialog("close");
				}
			}]
		});
		$("#xctdlgpic").dialog("open").dialog('setTitle', '现场图图片上传');
	});

	var tree_data = [{
		"id": 1,
		"text": "现场示意图",
		state: 'closed',
		"children": [{
				"id": 2,
				"text": "平面示意图",
			},
			{
				"id": 3,
				"text": "方位示意图",
				state: 'closed',
				"children": [{
					"id": 10,
					"text": "自绘方位示意图",

				}, {
					"id": 10,
					"text": "地图方位示意图",

				}],

			},

			{
				"id": 5,
				"text": "现场比列图",
				state: 'closed',
				"children": [{
					"id": 2,
					"text": "yy示意图",
				}, {
					"id": 3,
					"text": "zz示意图",

				}]
			}
		]
	}]
	$('#pictree').tree({
		data: tree_data,
		onDblClick: function(node) {
			if(node.children == undefined) {
				console.log(typesid);
					$("#"+typesid).val(node.text);
				$("#xctdlg").dialog("close");
			}
		}
	});

		
	//选择空值
	$("#selectnull").bind('click', function() {
		$("#"+typesid).val("");
		$("#xctdlg").dialog("close");

	});	

	$("#toInstall").bind('click', function() {
		var node=$("#pictree").tree('getSelected');
		//拿到最后一级
		if(node.children == undefined) {
			if(types.indexOf(node.id)!=-1){
				$.messager.alert('警告','已经设置为常用项，不能进行操作');
			}else{
					types.push(node.id);//添加标签
			
		var id=$("#pictree").tree('getSelected').id;
    var text=$("#pictree").tree('getSelected').text;
	var div = '<div id="'+id+'"><button id="'+id+'" class="easyui-linkbutton" type="button" onclick="xczhry_changyong_del(this)" iconCls="icon-cancel"></button>'+text+'</div>';
					$("#cyxdiv").append(div);
					$.parser.parse($("#cyxdiv").parent());

			}
			
		

}

	});

})
function xczhry_changyong_del(obj){
		$("#"+obj.id).remove();
		console.log(obj.id);
		for(var i=0;i<types.length;i++){
			if(types[i]==obj.id){
			delete types[i];
			}
	
		}


		
	}
//多文件上传
$('#xctf').filebox({
	onChange: function(value) {
		var f = $(this).next().find('input[type=file]')[0]; 
		if(f.files && f.files[0]) {
			// 更换图片时清空原图片展示内容
			      
			$('#pioimage').html('');       
			for(var i = 0; i < f.files.length; i++) {        
				var reader = new FileReader(f.files[i]);        
				reader.onload = function(e) {
					//append为在元素中的末尾添加内容
					          
					$('#pioimage').append("<img src='" + e.target.result + "' width='200px' height='100px'>");        
				}        
				reader.readAsDataURL(f.files[i]);
			}    
		}  
	}
})

$("#editHandInfo").click(function() {
	$("#handtableinfo").hide();
	$("#handtableinfo_edit").show();

})
$("#handedit_back").click(function() {
	$("#handtableinfo").show();
	$("#handtableinfo_edit").hide();
})

function dictselect(obj) {
   typesid=obj.id;
	$("#xctdlg").dialog("open").dialog('setTitle', '现场图片类型字典');
}
